<?php
/**
 * Created by PhpStorm.
 * User: trisatria
 * Date: 1/6/14
 * Time: 12:52 PM
 */

namespace Admin{
    use Admin\Model\AdminCategories;
    use Admin\Model\AdminCategoriesTable;

    define('REAL_TIME_REQUEST', 60000);

    define("ITEM_PER_PAGE", 10);

    define('STR_HIGHLIGHT_SIMPLE', 1);

    /**
     * Only match whole words in the string
     * (off by default)
     */
    define('STR_HIGHLIGHT_WHOLEWD', 2);

    /**
     * Case sensitive matching
     * (off by default)
     */
    define('STR_HIGHLIGHT_CASESENS', 4);

    /**
     * Overwrite links if matched
     * This should be used when the replacement string is a link
     * (off by default)
     */
    define('STR_HIGHLIGHT_STRIPLINKS', 8);

    use Admin\Model\AdminCommend;
    use Admin\Model\AdminCommendTable;

    use Admin\Model\AdminTopic;
    use Admin\Model\AdminTopicImg;
    use Admin\Model\AdminTopicImgTable;
    use Admin\Model\AdminTopicTable;


    use Admin\Model\AdminUserContact;
    use Admin\Model\AdminUserMessage;
    use Admin\Model\AdminUserMessageTable;
    use Zend\ModuleManager\ModuleManager;
    use Admin\Model\AdminUser;
    use Admin\Model\AdminUserTable;
    use Zend\Db\ResultSet\ResultSet;
    use Zend\Db\TableGateway\TableGateway;
    use Admin\Model\AdminFriendsTable;
    use Admin\Model\AdminFriends;
    use Admin\Model\AdminUserContactTable;

    use Admin\Model\AdminApp;
    use Admin\Model\AdminAppTable;

    use Admin\Model\AdminConfig;
    use Admin\Model\AdminConfigTable;

    use Admin\Model\AdminPage;
    use Admin\Model\AdminPageTable;

    use Admin\Model\AdminTag;
    use Admin\Model\AdminTagTable;

    use Admin\Model\AdminTopicTag;
    use Admin\Model\AdminTopicTagTable;


    class Module{

        /*static value array*/
        public static function getTopicShowPrice(){
            return array('1'=>'Show',
                '0'=>'Hide');
        }

        public static function getUserRoleName(){
            return array('1'=>'Admin',
                '2'=>'User');
        }

        public static function getUserStatusName(){
            return array('1'=>'Normally',
                '2'=>'Temporary Suspend',
                '3' => 'Suspended');
        }
        /*static value array*/

        public function init(ModuleManager $moduleManager)
        {
            $sharedEvents = $moduleManager->getEventManager()->getSharedManager();
            $sharedEvents->attach(__NAMESPACE__, 'dispatch', function($e) {
            }, 100);
        }

        public function getAutoloaderConfig()
        {
            return array(
                'Zend\Loader\ClassMapAutoloader' => array(
                    __DIR__ . '/autoload_classmap.php',
                ),
                'Zend\Loader\StandardAutoloader' => array(
                    'namespaces' => array(
                        __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                    ),
                ),
            );
        }

        public function getConfig()
        {
            return include __DIR__ . '/config/module.config.php';
        }

        //set layout for admin module
        public function onBootstrap($e)
        {
            $e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\Mvc\Controller\AbstractController', 'dispatch', function($e) {
                $controller      = $e->getTarget();
                $controllerClass = get_class($controller);
                $moduleNamespace = substr($controllerClass, 0, strpos($controllerClass, '\\'));
                $config          = $e->getApplication()->getServiceManager()->get('config');
                if (isset($config['module_layouts'][$moduleNamespace])) {
                    $controller->layout($config['module_layouts'][$moduleNamespace]);
                }
            }, 100);
        }

        // Add this method:
        public function getServiceConfig()
        {
            return array(
                'factories' => array(

                    'Admin\Model\AdminUserContactTable' =>  function($sm) {
                            $tableGateway = $sm->get('AdminUserContactTableGateway');
                            $table = new AdminUserContactTable($tableGateway);
                            return $table;
                        },
                    'AdminUserContactTableGateway' => function ($sm) {
                            $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                            $resultSetPrototype = new ResultSet();
                            $resultSetPrototype->setArrayObjectPrototype(new AdminUserContact());
                            return new TableGateway('user_contact', $dbAdapter, null, $resultSetPrototype);
                        },
                    'Admin\Model\AdminTagTable' =>  function($sm) {
                            $tableGateway = $sm->get('AdminTagTableGateway');
                            $table = new AdminTagTable($tableGateway);
                            return $table;
                        },
                    'AdminTagTableGateway' => function ($sm) {
                            $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                            $resultSetPrototype = new ResultSet();
                            $resultSetPrototype->setArrayObjectPrototype(new AdminTag());
                            return new TableGateway('tag', $dbAdapter, null, $resultSetPrototype);
                        },

                    'Admin\Model\AdminTopicTagTable' =>  function($sm) {
                            $tableGateway = $sm->get('AdminTopicTagTableGateway');
                            $table = new AdminTopicTagTable($tableGateway);
                            return $table;
                        },
                    'AdminTopicTagTableGateway' => function ($sm) {
                            $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                            $resultSetPrototype = new ResultSet();
                            $resultSetPrototype->setArrayObjectPrototype(new AdminTopicTag());
                            return new TableGateway('topic_tag', $dbAdapter, null, $resultSetPrototype);
                        },

                    'Admin\Model\AdminUserMessageTable' =>  function($sm) {
                            $tableGateway = $sm->get('AdminUserMessageTableGateway');
                            $table = new AdminUserMessageTable($tableGateway);
                            return $table;
                        },
                    'AdminUserMessageTableGateway' => function ($sm) {
                            $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                            $resultSetPrototype = new ResultSet();
                            $resultSetPrototype->setArrayObjectPrototype(new AdminUserMessage());
                            return new TableGateway('user_message', $dbAdapter, null, $resultSetPrototype);
                        },

                    'Admin\Model\AdminFriendsTable' =>  function($sm) {
                            $tableGateway = $sm->get('AdminFriendsTableGateway');
                            $table = new AdminFriendsTable($tableGateway);
                            return $table;
                        },
                    'AdminFriendsTableGateway' => function ($sm) {
                            $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                            $resultSetPrototype = new ResultSet();
                            $resultSetPrototype->setArrayObjectPrototype(new AdminFriends());
                            return new TableGateway('friend', $dbAdapter, null, $resultSetPrototype);
                        },

                    'Admin\Model\AdminTopicImgTable' =>  function($sm) {
                            $tableGateway = $sm->get('AdminTopicImgTableGateway');
                            $table = new AdminTopicImgTable($tableGateway);
                            return $table;
                        },
                    'AdminTopicImgTableGateway' => function ($sm) {
                            $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                            $resultSetPrototype = new ResultSet();
                            $resultSetPrototype->setArrayObjectPrototype(new AdminTopicImg());
                            return new TableGateway('topic_img', $dbAdapter, null, $resultSetPrototype);
                        },


                    'Admin\Model\AdminUserTable' =>  function($sm) {
                            $tableGateway = $sm->get('AdminUserTableGateway');
                            $table = new AdminUserTable($tableGateway);
                            return $table;
                        },
                    'AdminUserTableGateway' => function ($sm) {
                            $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                            $resultSetPrototype = new ResultSet();
                            $resultSetPrototype->setArrayObjectPrototype(new AdminUser());
                            return new TableGateway('user', $dbAdapter, null, $resultSetPrototype);
                        },

                    'Admin\Model\AdminTopicTable' =>  function($sm) {
                            $tableGateway = $sm->get('AdminTopicTableGateway');
                            $table = new AdminTopicTable($tableGateway);
                            return $table;
                        },
                    'AdminTopicTableGateway' => function ($sm) {
                            $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                            $resultSetPrototype = new ResultSet();
                            $resultSetPrototype->setArrayObjectPrototype(new AdminTopic());
                            return new TableGateway('topic', $dbAdapter, null, $resultSetPrototype);
                        },


                    'Admin\Model\AdminCommendTable' =>  function($sm) {
                            $tableGateway = $sm->get('AdminCommendTableGateway');
                            $table = new AdminCommendTable($tableGateway);
                            return $table;
                        },
                    'AdminCommendTableGateway' => function ($sm) {
                            $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                            $resultSetPrototype = new ResultSet();
                            $resultSetPrototype->setArrayObjectPrototype(new AdminCommend());
                            return new TableGateway('comment_topic', $dbAdapter, null, $resultSetPrototype);
                        },

                    'Admin\Model\AdminCategoriesTable' =>  function($sm) {
                            $tableGateway = $sm->get('AdminCategoriesTableGateway');
                            $table = new AdminCategoriesTable($tableGateway);
                            return $table;
                        },
                    'AdminCategoriesTableGateway' => function ($sm) {
                            $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                            $resultSetPrototype = new ResultSet();
                            $resultSetPrototype->setArrayObjectPrototype(new AdminCategories());
                            return new TableGateway('topic_cat', $dbAdapter, null, $resultSetPrototype);
                        },
                    'Admin\Model\AdminAppTable' =>  function($sm) {
                            $tableGateway = $sm->get('AdminAppTableGateway');
                            $table = new AdminAppTable($tableGateway);
                            return $table;
                        },
                    'AdminAppTableGateway' => function ($sm) {
                            $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                            $resultSetPrototype = new ResultSet();
                            $resultSetPrototype->setArrayObjectPrototype(new AdminApp());
                            return new TableGateway('appversion', $dbAdapter, null, $resultSetPrototype);
                        },
                    'Admin\Model\AdminConfigTable' =>  function($sm) {
                            $tableGateway = $sm->get('AdminConfigTableGateway');
                            $table = new AdminConfigTable($tableGateway);
                            return $table;
                        },
                    'AdminConfigTableGateway' => function ($sm) {
                            $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                            $resultSetPrototype = new ResultSet();
                            $resultSetPrototype->setArrayObjectPrototype(new AdminConfig());
                            return new TableGateway('config', $dbAdapter, null, $resultSetPrototype);
                        },
                    'Admin\Model\AdminPageTable' =>  function($sm) {
                            $tableGateway = $sm->get('AdminPageTableGateway');
                            $table = new AdminPageTable($tableGateway);
                            return $table;
                        },
                    'AdminPageTableGateway' => function ($sm) {
                            $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                            $resultSetPrototype = new ResultSet();
                            $resultSetPrototype->setArrayObjectPrototype(new AdminPage());
                            return new TableGateway('page', $dbAdapter, null, $resultSetPrototype);
                        },

                ),
            );
        }

    }
}